import request from '@/utils/request'

/**
 * 考试列表
 */
export const getExam = (query) => {
        return request({
            url: '/exam/',
            method: 'get',
            params: query
        })
    }
/**
 * 当前用户考试列表
 */
export const getExamOwn = (query) => {
        return request({
            url: '/exam/',
            method: 'get',
            params: query
        })
    }
    /**
     * 考试状态刷新
     */
export const ExamCheck = () => {
    return request({
        url: '/ExamCheck/',
        method: 'get'
    })
}

/**
 * 考试详情
 */
export const examDetail = (data) => {
        return request({
            url: '/exam/' + data + '/',
            method: 'get'
        })
    }
    /**
     * 课程题目内数
     */
export const questionStatistics = (query) => {
        return request({
            url: '/questionstatistics/',
            method: 'get',
            params: query
        })
    }
    /**
     * x新增试卷
     */
export const addExam = (data) => {
        return request({
            url: '/exam/',
            method: 'post',
            data: data
        })
    }
    /**
     * 删除
     */
export const delExam = (id) => {
        return request({
            url: '/exam/' + id + '/',
            method: 'delete',

        })
    }
    /**
     *修改试卷
     */
export const updateExam = (data) => {
    return request({
        url: '/exam/' + data.id + '/',
        method: 'put',
        data: data
    })
}

/**
 * 试卷详情
 * @param data
 */
export function paperDetail(id) {
    return request({
        url: '/answersheet/' + id + '/',
        method: 'get'
    })
}
export function paperList(query) {
    return request({
        url: '/paper/',
        method: 'get',
        params: query
    })
}
export function paperResult(id) {
    return request({
        url: '/paper/' + id + '/',
        method: 'get'
    })
}
/**
 * 提交答案
 */
export const fillAnswer = (data, type) => {
        return request({
            url: `/${type}/`,
            method: 'post',
            data: data
        })
    }
    /**
     * 答案详情
     */
export const answerDetail = (type, question, paper) => {
    return request({
        url: `/${type}/?question=${question}&paper=${paper}`,
        method: 'get',

    })
}
export const answerDetailId = (type, id) => {
        return request({
            url: `/${type}/` + id + '/',
            method: 'get',

        })
    }
    /**
     * 修改答案
     */
export const answerUpdate = (data, type, id) => {
        return request({
            url: `/${type}/` + id + '/',
            method: 'put',
            data: data
        })
    }
    /**
     * 交卷
     */
export const handExam = (id, data) => {
    return request({
        url: '/answersheet/' + id + '/',
        method: 'put',
        data: data
    })
}



/**
 * 题库详情
 * @param data
 */
export function fetchDetail(id) {
    return post('/exam/api/exam/exam/detail', { id: id })
}

/**
 * 保存题库
 * @param data
 */
export function saveData(data) {
    return post('/exam/api/exam/exam/save', data)
}

/**
 * 获取所有考试结果统计
 */
export const examResultAll = (query) => {
    return request({
        url: '/examResult/',
        method: 'get',
        params: query
    })
}